const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack')
// common js 的到成绩语法
module.exports = {
  mode: 'development',
  devtool: 'source-map',
  entry: {
    main: './src/index.js'
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].bundle.js',
    publicPath: '/'
  },
  plugins: [new HtmlWebpackPlugin({
    template: './src/index.html'
  }),
  // 热更新
  new webpack.HotModuleReplacementPlugin()],
  devServer: {
    contentBase: path.join(__dirname, "dist"),
    compress: true,
    port: 9000,
    open: true,
    // 热更新
    hot: true,
    hotOnly: true
  },
  module: {
    rules: [
      // babel 配置
      { test: /\.js$/, exclude: /node_modules/, loader: "babel-loader", options: { "presets": ["@babel/preset-env"] } },
      {
        test: /\.css$/,
        use: [
          // 执行顺序 从下到上 从右向左
          { loader: "style-loader" },
          { loader: "css-loader" },
          { loader: "postcss-loader" }
        ]
      }
    ]
  },
}